
#pragma once

#include "General Structures.hpp"
#include "Vector2D.h"
#include "OpenGL.hpp"
#include "ClippingPlane.h"
#include "MapGenerator.h"
#include <list>
#include <vector>
#include <fstream>
#include <string>
#include <map>
using namespace std;

class Minimap
{
	public:
		Minimap();
		Minimap(ClippingPlane* pClippingPlane);
		
		// Customimization (MAKE SURE SetSurroundDistance IS CALlED FIRST)
		inline void SetLocation(int x, int y)	{m_OriginalPosition.x = x; m_OriginalPosition.y = y;}	// Set the location of the minimap
		//inline void SetSideLength(int sideLength)	{m_OriginalDimensions.w = sideLength; m_OriginalDimensions.h = sideLength;}	// The side length is how big the minimap "square" is
		inline void SetSurroundDistance(int surroundDistance)	{m_SurroundDistance = surroundDistance;} // The distance between the texture and m_Position
		void RecomputeTexturePosition(); // Sets the position of the texture
		
		// Based on the mouse's position, this function recalculates the location of the clipping plane.  It ensures that the mouse is within the minimap
		void HandleScrolling(const Vector2D& mouse);

		// Based on the mouse's position, this function gives the position in world coordinates
		Vector2D GetWorldPosFromMousePos(const Vector2D& mouse);

		// Returns true if the mouse is in the bounds of the minimap
		bool inBounds(int x, int y);

		// Returns the dimensions of the minimap
		inline Dimension GetDimensions() {return m_TextureDimensions;}

		// Rendering functions
		void RenderMinimap();
		void RenderMinimap(list<Room>* rooms);
		void RenderScreen();
		void RenderEntities();

		// Texture Functions
		void Load(const string& filename);  // Load in map data
		void Load(const vector<vector<list<int>>>& map); // Load in map data
		void Load(const Room& room);
		void Remove(const Room& room);
		void Delete();

		// Entity functions
		void UpdateEntity(int ID, const Vector2D& position); // Updates an entity's position.
		void AddEntity(int ID, const Vector2D& position, const OGL_Color& color); // Add a new entity
		void RemoveEntity(int ID); // Removes the entity from the minimap

	private:
		ClippingPlane *m_pClipPlane; // our clipping plane

		// location / customization
		Vector2D m_TexturePosition, // where the texture is actually located
			m_OriginalPosition, // the position specified by the user
			m_TextureClippingPercentage; // what percentage of the texture is actually the minimap, ie: 60% of the texture is minimap, while 40% is blank (to get a texture that is a power of two)
		Dimension m_TextureDimensions, // the dimensions of the texture
			m_OriginalDimensions, // the dimensions specified by the user
			m_MapDimensions; // the number of tiles on the loaded map, ie: 100x100

		int m_SurroundDistance; // the distance between the texture and m_Position
		float m_TextureRatio; // The texture ratio tells the Render function what shape of rectange to render the texture as.  It is h/w.  > 0 implies displace Y; < 0 implies displace X

		// minimap texture
		GLuint m_Texture;		// so we can render the minimap
		bool m_IsBuilt;			// are we able to render?

		// entities
		struct ColoredCoords { // we create a new struct because each entity can be displayed with a different color
			Coords coords;
			OGL_Color color;
		};
		map<int, ColoredCoords> m_Entities;  // contains all of our entities
		map<int, GLuint> m_RoomTextureMap; // this map contains a list of room ID's and its corresponding texture ID
};
